import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] arr = new int[n][2];

        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                arr[i][j] = in.nextInt();
            }
        }

        Arrays.sort(arr , (v1 , v2) -> {
            return v1[0] <= v2[0] ? -1 : 1;
        });

        PriorityQueue<Integer> q = new PriorityQueue<>();
        q.offer(arr[0][1]);

        for(int i = 1; i < n; i++){
            int a = arr[i][0] , b = arr[i][1];
            if(a >= q.peek()){
                q.offer(b);
            }else{
                q.offer(Math.min(b , q.poll()));
            }
        }
        System.out.println(q.size());

    }
}